Conditions | 6 |
Paths | 579 |
Total Lines | 60 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var whois = require('../common/whoiswrapper.js'), |
||
19 | ipcRenderer.on('sw:results', function(event, domainResults) { |
||
20 | const { |
||
21 | isDomainAvailable |
||
22 | } = whois; |
||
23 | var domainStatus, domainResultsJSON; |
||
24 | //ipcRenderer.send('app:debug', "Whois domain reply:\n {0}".format(domainResults)); |
||
25 | |||
26 | domainResultsJSON = (function() { |
||
27 | var result; |
||
28 | if (typeof domainResults === 'object') { |
||
29 | JSON.stringify(domainResults, null, 2); |
||
30 | result = domainResults.map(function(data) { |
||
31 | data.data = parseRawData(data.data); |
||
32 | return data; |
||
33 | }); |
||
34 | } else { |
||
35 | result = parseRawData(domainResults); |
||
36 | } |
||
37 | return result; |
||
38 | })(); |
||
39 | |||
40 | // Check domain status |
||
41 | domainStatus = isDomainAvailable(domainResults); |
||
42 | |||
43 | switch (domainStatus) { |
||
44 | case 'querylimituniregistry': |
||
45 | case 'error': |
||
46 | $('#swMessageWhoisResults').text("Whois error: {0}\n{1}".format(domainStatus, domainResults)); |
||
47 | $('#swMessageError').removeClass('is-hidden'); |
||
48 | break; |
||
49 | case 'unavailable': |
||
50 | console.log(domainResultsJSON); |
||
|
|||
51 | $('#swMessageUnavailable').removeClass('is-hidden'); |
||
52 | $('#swMessageWhoisResults').text(domainResults); |
||
53 | |||
54 | $('#swTdDomain').attr('url', "http://" + domainResultsJSON['domainName'] || domainResultsJSON['domain']); |
||
55 | $('#swTdDomain').text(domainResultsJSON['domainName'] || domainResultsJSON['domain']); |
||
56 | |||
57 | console.log(domainResultsJSON['registrarRegistrationExpirationDate'] || domainResultsJSON['expires'] || domainResultsJSON['registryExpiryDate']); |
||
58 | $('#swTdUpdate').text(getDate(domainResultsJSON['updatedDate'] || domainResultsJSON['lastUpdated'])); |
||
59 | $('#swTdRegistrar').text(domainResultsJSON['registrar']); |
||
60 | $('#swTdCreation').text(getDate(domainResultsJSON['creationDate'] || domainResultsJSON['createdDate'] || domainResultsJSON['created'])); |
||
61 | $('#swTdCompany').text(domainResultsJSON['registrantOrganization'] || domainResultsJSON['registrant']); |
||
62 | $('#swTdExpiry').text(getDate(domainResultsJSON['expires'] || domainResultsJSON['registryExpiryDate'] || domainResultsJSON['expiryDate'] || domainResultsJSON['registrarRegistrationExpirationDate'])); |
||
63 | $('#swTableWhoisinfo.is-hidden').removeClass('is-hidden'); |
||
64 | break; |
||
65 | case 'available': |
||
66 | $('#swMessageWhoisResults').text(domainResults); |
||
67 | $('#swMessageAvailable').removeClass('is-hidden'); |
||
68 | break; |
||
69 | default: |
||
70 | $('#swMessageWhoisResults').text("Whois default error\n{0}".format(domainResults)); |
||
71 | $('#swMessageError').removeClass('is-hidden'); |
||
72 | break; |
||
73 | } |
||
74 | |||
75 | $('#swSearchButtonSearch').removeClass('is-loading'); |
||
76 | $('#swSearchInputDomain').removeAttr('readonly'); |
||
77 | |||
78 | }); |
||
79 | |||
143 |